package com.power.home.presenter;

import com.power.home.common.util.UIUtil;
import com.power.home.data.bean.ConvertCodeListItemBean;
import com.power.home.data.bean.ConvertRecordOutBean;
import com.power.home.data.bean.CreateCodeBean;
import com.power.home.net.rto_exception.ApiException;
import com.power.home.net.rto_rxbuild.RxHttpReponseCompat;
import com.power.home.net.rto_subscriber.ProgressSubcriber;
import com.power.home.presenter.contract.ConvertRecordContract;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.annotations.NonNull;

/**
 * Created by ZHP on 2017/7/19.
 */

public class ConvertRecordPresenter extends BasePresenter<ConvertRecordContract.IConvertRecordModel, ConvertRecordContract.View> {

    @Inject
    public ConvertRecordPresenter(ConvertRecordContract.IConvertRecordModel iConvertRecordModel, ConvertRecordContract.View view) {
        super(iConvertRecordModel, view);
    }

    public void getCodeMarketRecord(int page, int size) {
        mModel.getCodeMarketRecord(page, size).compose(RxHttpReponseCompat.<ConvertRecordOutBean>compatResult())
                .subscribe(new ProgressSubcriber<ConvertRecordOutBean>(mContext, mView) {
                    @Override
                    public void onNext(ConvertRecordOutBean convertRecordOutBean) {
                        if (hasView()) {
                            mView.getCodeMarketRecordSuccess(convertRecordOutBean.getContent());
                        }
                    }
                });
    }

    public void createCodeMarket(){
        mModel.codeMarketGenerate().compose(RxHttpReponseCompat.<CreateCodeBean>compatResult())
                .subscribe(new ProgressSubcriber<CreateCodeBean>(mContext,mView) {
                    @Override
                    public void onNext(@NonNull CreateCodeBean createCodeBean) {
                        if(hasView()){
                            mView.codeMarketGenerateSuccess(createCodeBean);
                        }
                    }


                });
    }

    public void codeMarketList(Boolean useStatus ,int page,int size){
        mModel.codeMarketList(useStatus,page,size).compose(RxHttpReponseCompat.<List<ConvertCodeListItemBean>>compatResult())
                .subscribe(new ProgressSubcriber<List<ConvertCodeListItemBean>>(mContext,mView) {
                    @Override
                    public void onNext(@NonNull List<ConvertCodeListItemBean> convertCodeListItemBeans) {
                        if(hasView()){
                            mView.codeMarketListSuccess(convertCodeListItemBeans);
                        }

                    }
                });
    }


}
